#include"mythread.h"


int main(int argc, char* argv[])
{
	int opt;
    char** message = (char**)malloc(2 * sizeof(char*));
    message[0] = (char*)malloc(5 * sizeof(char));
    message[1] = (char*)malloc(5 * sizeof(char));
	if (argc == 1)
	{
		opt = LS_NONE;
        message[0] = ".";
        message[1] = (char *)(&opt);
        int rel = createDoLsThread(message);
        if (rel == -1) return 0;
	}
	else
	{
		int mode = LS_NONE;                    // 默认为无参数ls  
        int have_file_param = 0;               // 是否有输入文件参数

 
        while(argc > 1)
        {
            argc--;
            argv++;

            int calMode = analyze_param(*argv);
            if(calMode != -1)
            {
                mode += calMode;
            }
            else
            {
                have_file_param = 1;
                do
                { 
                    pthread_t childThread;
                    message[0] = *argv;
                    message[1] = (char *)(&mode);
                    int rel = createDoLsThread(message);
                    if (rel == -1) return 0;

                    argc--;
                    argv++;
                } while(argc >= 1);
            }
            if (!have_file_param)  
            {
                message[0] = ".";
                message[1] = (char *)(&mode);
                int rel = createDoLsThread(message);
                if (rel == -1) return 0;
            }
        }
	}

	return 0;
}